const path = require('path')
const Koa = require('koa')
const app = new Koa()
const koaBody = require('koa-body')
const views = require('koa-views')
const serve = require('koa-static')

const Router = require('@koa/router')
const router = new Router()
const routerIndex = require('./routes/index')
const routerSign = require('./routes/sign')

app.use(serve(path.resolve(__dirname, './public')))

// 加载模板引擎
app.use(views(path.join(__dirname, './views'), {
  extension: 'ejs'
}))

// 获取客户端的数据
app.use(koaBody())

// 挂载路由
router.use('/weixin', routerIndex.routes())
router.use('/api', routerSign.routes())
app.use(router.routes())

app.listen(3333, 'localhost', () => {
  console.log('localhost:3333')
})